package com.swing.sky.common.web;

import org.springframework.http.HttpStatus;
import java.util.HashMap;
import java.util.Map;
public class SkyResponse {
    private Integer status;
    private String msg;
    private Map<String, Object> body;

    @Override
    public String toString() {
        return "RestResponse{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", body=" + body +
                '}';
    }
    public static SkyResponse getInstance(HttpStatus status, String message) {
        return new SkyResponse(status.value(), message, null);
    }
    public static SkyResponse success() {
        return new SkyResponse(HttpStatus.OK.value(), "\u8BF7\u6C42\u6210\u529F\uFF01", null);
    }
    public static SkyResponse success(int length) {
        return new SkyResponse(HttpStatus.OK.value(), "\u8BF7\u6C42\u6210\u529F\uFF01", new HashMap<>(length));
    }
    public static SkyResponse success(String message) {
        return new SkyResponse(HttpStatus.OK.value(), message, null);
    }
    public static SkyResponse success(String message, int length) {
        return new SkyResponse(HttpStatus.OK.value(), message, new HashMap<>(length));
    }
    public static SkyResponse fail(HttpStatus status, String msg) {
        return new SkyResponse(status.value(), msg, null);
    }
    public SkyResponse put(String key, Object value) {
        this.body.put(key, value);
        return this;
    }
    public SkyResponse() {}
    public SkyResponse(Integer status, String msg, Map<String, Object> body) {
        this.status = status;
        this.msg = msg;
        this.body = body;
    }
    public Integer getStatus() {return status;}
    public void setStatus(Integer status) {this.status = status;}
    public String getMsg() {return msg;}
    public void setMsg(String msg) {this.msg = msg;}
    public Map<String, Object> getBody() {return body;}
    public void setBody(Map<String, Object> body) {this.body = body;}
}